/**
 * Generate code from /{{projectName}}-core/src/main/java/{{packageName}}/{{apis}}/rest/Abstract{{apiEntities}}Resource.java.hbs
 */
package cn.ibizlab.api.rest;

import java.util.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.SpringQueryMap;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.http.HttpStatus;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.util.ObjectUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.access.prepost.PostAuthorize;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.ApiOperation;
import cn.ibizlab.util.domain.ImportResult;
import cn.ibizlab.api.dto.*;
import cn.ibizlab.api.mapping.*;
import cn.ibizlab.core.ad.domain.SysDepartment;
import cn.ibizlab.core.ad.service.SysDepartmentService;
import cn.ibizlab.core.ad.filter.SysDepartmentSearchContext;
import cn.ibizlab.util.annotation.VersionCheck;

/**
 * 实体[SysDepartment] rest实现
 *
 * @author generator
 */
@Slf4j
public abstract class AbstractSysDepartmentResource {

    @Autowired
    public SysDepartmentService sysDepartmentService;

    @Autowired
    @Lazy
    public SysDepartmentDTOMapping sysDepartmentDtoMapping;

    @Autowired
    @Lazy
    public SysDepartmentFilterDTOMapping sysDepartmentFilterDtoMapping;


    /**
    * 创建Create 部门
    * 
    *
    * @param dto dto
    * @return ResponseEntity<SysDepartmentDTO>
    */
    @ApiOperation(value = "创建Create", tags = {"部门" },  notes = "SysDepartment-Create ")
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','uaa-SysDepartment-Create-all') or hasPermission(this.sysDepartmentDtoMapping.toDomain(#dto),'uaa-SysDepartment-Create')")
    @PostMapping(value = {"sys_departments","sys_departments"})
    public ResponseEntity<SysDepartmentDTO> create
            (@Validated @RequestBody SysDepartmentDTO dto) {
        SysDepartment domain = sysDepartmentDtoMapping.toDomain(dto);
        sysDepartmentService.create(domain);
        SysDepartment rt = domain;
        return ResponseEntity.status(HttpStatus.OK).body(sysDepartmentDtoMapping.toDto(rt));
    }

    /**
    * 获取Get 部门
    * 
    *
    * @param id id
    * @return ResponseEntity<SysDepartmentDTO>
    */
    @ApiOperation(value = "获取Get", tags = {"部门" },  notes = "SysDepartment-Get ")
    @PostAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','uaa-SysDepartment-Get-all') or hasPermission(this.sysDepartmentDtoMapping.toDomain(returnObject.body),'uaa-SysDepartment-Get')")
    @GetMapping("sys_departments/{id}")
    public ResponseEntity<SysDepartmentDTO> getById
            (@PathVariable("id") String id) {
        SysDepartment rt = sysDepartmentService.get(id);
        return ResponseEntity.status(HttpStatus.OK).body(sysDepartmentDtoMapping.toDto(rt));
    }

    /**
    * 删除Remove 部门
    * 
    *
    * @param id id
    * @return ResponseEntity<Boolean>
    */
    @ApiOperation(value = "删除Remove", tags = {"部门" },  notes = "SysDepartment-Remove ")
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','uaa-SysDepartment-Remove-all') or hasPermission(this.sysDepartmentService.get(#id),'uaa-SysDepartment-Remove')")
    @DeleteMapping("sys_departments/{id}")
    public ResponseEntity<Boolean> removeById
            (@PathVariable("id") String id) {
        Boolean rt = sysDepartmentService.remove(id);
        return ResponseEntity.status(HttpStatus.OK).body(rt);
    }

    /**
    * 更新Update 部门
    * 
    *
    * @param id id
    * @param dto dto
    * @return ResponseEntity<SysDepartmentDTO>
    */
    @ApiOperation(value = "更新Update", tags = {"部门" },  notes = "SysDepartment-Update ")
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','uaa-SysDepartment-Update-all') or hasPermission(this.sysDepartmentService.get(#id),'uaa-SysDepartment-Update')")
    @VersionCheck(entity = "sysdepartment" , versionfield = "updateTime")
    @PutMapping("sys_departments/{id}")
    public ResponseEntity<SysDepartmentDTO> updateById
            (@PathVariable("id") String id, @Validated @RequestBody SysDepartmentDTO dto) {
        SysDepartment domain = sysDepartmentDtoMapping.toDomain(dto);
        domain.setId(id);
        sysDepartmentService.update(domain);
        SysDepartment rt = domain;
        return ResponseEntity.status(HttpStatus.OK).body(sysDepartmentDtoMapping.toDto(rt));
    }

    /**
    * Cache_evict 部门
    * 
    *
    * @param dto dto
    * @return ResponseEntity<SysDepartmentDTO>
    */
    @ApiOperation(value = "Cache_evict", tags = {"部门" },  notes = "SysDepartment-Cache_evict ")
    @PostMapping("sys_departments/cache_evict")
    public ResponseEntity<SysDepartmentDTO> cacheEvict
            (@Validated @RequestBody SysDepartmentDTO dto) {
        SysDepartment domain = sysDepartmentDtoMapping.toDomain(dto);
        SysDepartment rt = sysDepartmentService.cacheEvict(domain);
        return ResponseEntity.status(HttpStatus.OK).body(sysDepartmentDtoMapping.toDto(rt));
    }

    /**
    * 校验CheckKey 部门
    * 
    *
    * @param dto dto
    * @return ResponseEntity<Integer>
    */
    @ApiOperation(value = "校验CheckKey", tags = {"部门" },  notes = "SysDepartment-CheckKey ")
    @PostMapping("sys_departments/checkkey")
    public ResponseEntity<Integer> checkKey
            (@Validated @RequestBody SysDepartmentDTO dto) {
        SysDepartment domain = sysDepartmentDtoMapping.toDomain(dto);
        Integer rt = sysDepartmentService.checkKey(domain);
        return ResponseEntity.status(HttpStatus.OK).body(rt);
    }

    /**
    * 草稿GetDraft 部门
    * 
    *
    * @param dto dto
    * @return ResponseEntity<SysDepartmentDTO>
    */
    @ApiOperation(value = "草稿GetDraft", tags = {"部门" },  notes = "SysDepartment-GetDraft ")
    @GetMapping("sys_departments/getdraft")
    public ResponseEntity<SysDepartmentDTO> getDraft
            (@SpringQueryMap SysDepartmentDTO dto) {
        SysDepartment domain = sysDepartmentDtoMapping.toDomain(dto);
        SysDepartment rt = sysDepartmentService.getDraft(domain);
        return ResponseEntity.status(HttpStatus.OK).body(sysDepartmentDtoMapping.toDto(rt));
    }

    /**
    * options 部门
    * 
    *
    * @param dto dto
    * @return ResponseEntity<List<SysDepartmentDTO>>
    */
    @ApiOperation(value = "options", tags = {"部门" },  notes = "SysDepartment-options ")
    @PostMapping("sys_departments/options")
    public ResponseEntity<List<SysDepartmentDTO>> options
            (@Validated @RequestBody SysDepartmentDTO dto) {
        SysDepartment domain = sysDepartmentDtoMapping.toDomain(dto);
        List<SysDepartment> rt = sysDepartmentService.options(domain);
        return ResponseEntity.status(HttpStatus.OK).body(sysDepartmentDtoMapping.toDto(rt));
    }

    /**
    * ParentIds 部门
    * 
    *
    * @param id id
    * @param dto dto
    * @return ResponseEntity<List<String>>
    */
    @ApiOperation(value = "ParentIds", tags = {"部门" },  notes = "SysDepartment-ParentIds ")
    @PostMapping("sys_departments/{id}/parentids")
    public ResponseEntity<List<String>> parentIdsById
            (@PathVariable("id") String id, @Validated @RequestBody SysDepartmentDTO dto) {
        SysDepartment domain = sysDepartmentDtoMapping.toDomain(dto);
        domain.setId(id);
        List<String> rt = sysDepartmentService.parentIds(domain);
        return ResponseEntity.status(HttpStatus.OK).body(rt);
    }

    /**
    * 保存Save 部门
    * 
    *
    * @param dto dto
    * @return ResponseEntity<SysDepartmentDTO>
    */
    @ApiOperation(value = "保存Save", tags = {"部门" },  notes = "SysDepartment-Save ")
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','uaa-SysDepartment-Save-all') or hasPermission(this.sysDepartmentDtoMapping.toDomain(#dto),'uaa-SysDepartment-Save')")
    @PostMapping("sys_departments/save")
    public ResponseEntity<SysDepartmentDTO> save
            (@Validated @RequestBody SysDepartmentDTO dto) {
        SysDepartment domain = sysDepartmentDtoMapping.toDomain(dto);
        sysDepartmentService.save(domain);
        SysDepartment rt = domain;
        return ResponseEntity.status(HttpStatus.OK).body(sysDepartmentDtoMapping.toDto(rt));
    }

    /**
    * SubIds 部门
    * 
    *
    * @param id id
    * @param dto dto
    * @return ResponseEntity<List<String>>
    */
    @ApiOperation(value = "SubIds", tags = {"部门" },  notes = "SysDepartment-SubIds ")
    @PostMapping("sys_departments/{id}/subids")
    public ResponseEntity<List<String>> subIdsById
            (@PathVariable("id") String id, @Validated @RequestBody SysDepartmentDTO dto) {
        SysDepartment domain = sysDepartmentDtoMapping.toDomain(dto);
        domain.setId(id);
        List<String> rt = sysDepartmentService.subIds(domain);
        return ResponseEntity.status(HttpStatus.OK).body(rt);
    }

    /**
    * 查询FetchDefault 部门
    * 
    *
    * @param dto dto
    * @return ResponseEntity<List<SysDepartmentDTO>>
    */
    @ApiOperation(value = "查询FetchDefault", tags = {"部门" },  notes = "SysDepartment-FetchDefault ")
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','uaa-SysDepartment-FetchDefault-all') or hasPermission(#dto,'uaa-SysDepartment-FetchDefault')")
    @PostMapping("sys_departments/fetchdefault")
    public ResponseEntity<List<SysDepartmentDTO>> fetchDefault
            (@Validated @RequestBody SysDepartmentFilterDTO dto) {
        SysDepartmentSearchContext context = sysDepartmentFilterDtoMapping.toDomain(dto);
        Page<SysDepartment> domains = sysDepartmentService.searchDefault(context) ;
        List<SysDepartmentDTO> list = sysDepartmentDtoMapping.toDto(domains.getContent());
            return ResponseEntity.status(HttpStatus.OK)
            .header("x-page", String.valueOf(context.getPageable().getPageNumber()))
            .header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
            .header("x-total", String.valueOf(domains.getTotalElements()))
            .body(list);
    }

    /**
    * 查询FetchNesteds 部门
    * 
    *
    * @param dto dto
    * @return ResponseEntity<List<SysDepartmentDTO>>
    */
    @ApiOperation(value = "查询FetchNesteds", tags = {"部门" },  notes = "SysDepartment-FetchNesteds ")
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','uaa-SysDepartment-FetchNesteds-all') or hasPermission(#dto,'uaa-SysDepartment-FetchNesteds')")
    @PostMapping("sys_departments/fetchnesteds")
    public ResponseEntity<List<SysDepartmentDTO>> fetchNesteds
            (@Validated @RequestBody SysDepartmentFilterDTO dto) {
        SysDepartmentSearchContext context = sysDepartmentFilterDtoMapping.toDomain(dto);
        Page<SysDepartment> domains = sysDepartmentService.searchNesteds(context) ;
        List<SysDepartmentDTO> list = sysDepartmentDtoMapping.toDto(domains.getContent());
            return ResponseEntity.status(HttpStatus.OK)
            .header("x-page", String.valueOf(context.getPageable().getPageNumber()))
            .header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
            .header("x-total", String.valueOf(domains.getTotalElements()))
            .body(list);
    }

    /**
    * 创建Create 部门
    * 
    *
    * @param organizationId organizationId
    * @param dto dto
    * @return ResponseEntity<SysDepartmentDTO>
    */
    @ApiOperation(value = "创建Create", tags = {"部门" },  notes = "SysDepartment-Create ")
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','uaa-SysDepartment-Create-all') or hasPermission(this.sysDepartmentDtoMapping.toDomain(#dto),'uaa-SysDepartment-Create')")
    @PostMapping(value = {"sys_organizations/{organizationId}/sys_departments","sys_organizations/{organizationId}/sys_departments"})
    public ResponseEntity<SysDepartmentDTO> createByOrganizationId
            (@PathVariable("organizationId") String organizationId, @Validated @RequestBody SysDepartmentDTO dto) {
        SysDepartment domain = sysDepartmentDtoMapping.toDomain(dto);
        domain.setOrganizationId(organizationId);
        sysDepartmentService.create(domain);
        SysDepartment rt = domain;
        return ResponseEntity.status(HttpStatus.OK).body(sysDepartmentDtoMapping.toDto(rt));
    }

    /**
    * 获取Get 部门
    * 
    *
    * @param organizationId organizationId
    * @param id id
    * @return ResponseEntity<SysDepartmentDTO>
    */
    @ApiOperation(value = "获取Get", tags = {"部门" },  notes = "SysDepartment-Get ")
    @PostAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','uaa-SysDepartment-Get-all') or hasPermission(this.sysDepartmentDtoMapping.toDomain(returnObject.body),'uaa-SysDepartment-Get')")
    @GetMapping("sys_organizations/{organizationId}/sys_departments/{id}")
    public ResponseEntity<SysDepartmentDTO> getByOrganizationIdAndId
            (@PathVariable("organizationId") String organizationId, @PathVariable("id") String id) {
        SysDepartment rt = sysDepartmentService.get(id);
        return ResponseEntity.status(HttpStatus.OK).body(sysDepartmentDtoMapping.toDto(rt));
    }

    /**
    * 删除Remove 部门
    * 
    *
    * @param organizationId organizationId
    * @param id id
    * @return ResponseEntity<Boolean>
    */
    @ApiOperation(value = "删除Remove", tags = {"部门" },  notes = "SysDepartment-Remove ")
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','uaa-SysDepartment-Remove-all') or hasPermission(this.sysDepartmentService.get(#id),'uaa-SysDepartment-Remove')")
    @DeleteMapping("sys_organizations/{organizationId}/sys_departments/{id}")
    public ResponseEntity<Boolean> removeByOrganizationIdAndId
            (@PathVariable("organizationId") String organizationId, @PathVariable("id") String id) {
        Boolean rt = sysDepartmentService.remove(id);
        return ResponseEntity.status(HttpStatus.OK).body(rt);
    }

    /**
    * 更新Update 部门
    * 
    *
    * @param organizationId organizationId
    * @param id id
    * @param dto dto
    * @return ResponseEntity<SysDepartmentDTO>
    */
    @ApiOperation(value = "更新Update", tags = {"部门" },  notes = "SysDepartment-Update ")
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','uaa-SysDepartment-Update-all') or hasPermission(this.sysDepartmentService.get(#id),'uaa-SysDepartment-Update')")
    @VersionCheck(entity = "sysdepartment" , versionfield = "updateTime")
    @PutMapping("sys_organizations/{organizationId}/sys_departments/{id}")
    public ResponseEntity<SysDepartmentDTO> updateByOrganizationIdAndId
            (@PathVariable("organizationId") String organizationId, @PathVariable("id") String id, @Validated @RequestBody SysDepartmentDTO dto) {
        SysDepartment domain = sysDepartmentDtoMapping.toDomain(dto);
        domain.setId(id);
        sysDepartmentService.update(domain);
        SysDepartment rt = domain;
        return ResponseEntity.status(HttpStatus.OK).body(sysDepartmentDtoMapping.toDto(rt));
    }

    /**
    * Cache_evict 部门
    * 
    *
    * @param organizationId organizationId
    * @param dto dto
    * @return ResponseEntity<SysDepartmentDTO>
    */
    @ApiOperation(value = "Cache_evict", tags = {"部门" },  notes = "SysDepartment-Cache_evict ")
    @PostMapping("sys_organizations/{organizationId}/sys_departments/cache_evict")
    public ResponseEntity<SysDepartmentDTO> cacheEvictByOrganizationId
            (@PathVariable("organizationId") String organizationId, @Validated @RequestBody SysDepartmentDTO dto) {
        SysDepartment domain = sysDepartmentDtoMapping.toDomain(dto);
        domain.setOrganizationId(organizationId);
        SysDepartment rt = sysDepartmentService.cacheEvict(domain);
        return ResponseEntity.status(HttpStatus.OK).body(sysDepartmentDtoMapping.toDto(rt));
    }

    /**
    * 校验CheckKey 部门
    * 
    *
    * @param organizationId organizationId
    * @param dto dto
    * @return ResponseEntity<Integer>
    */
    @ApiOperation(value = "校验CheckKey", tags = {"部门" },  notes = "SysDepartment-CheckKey ")
    @PostMapping("sys_organizations/{organizationId}/sys_departments/checkkey")
    public ResponseEntity<Integer> checkKeyByOrganizationId
            (@PathVariable("organizationId") String organizationId, @Validated @RequestBody SysDepartmentDTO dto) {
        SysDepartment domain = sysDepartmentDtoMapping.toDomain(dto);
        domain.setOrganizationId(organizationId);
        Integer rt = sysDepartmentService.checkKey(domain);
        return ResponseEntity.status(HttpStatus.OK).body(rt);
    }

    /**
    * 草稿GetDraft 部门
    * 
    *
    * @param organizationId organizationId
    * @param dto dto
    * @return ResponseEntity<SysDepartmentDTO>
    */
    @ApiOperation(value = "草稿GetDraft", tags = {"部门" },  notes = "SysDepartment-GetDraft ")
    @GetMapping("sys_organizations/{organizationId}/sys_departments/getdraft")
    public ResponseEntity<SysDepartmentDTO> getDraftByOrganizationId
            (@PathVariable("organizationId") String organizationId, @SpringQueryMap SysDepartmentDTO dto) {
        SysDepartment domain = sysDepartmentDtoMapping.toDomain(dto);
        domain.setOrganizationId(organizationId);
        SysDepartment rt = sysDepartmentService.getDraft(domain);
        return ResponseEntity.status(HttpStatus.OK).body(sysDepartmentDtoMapping.toDto(rt));
    }

    /**
    * options 部门
    * 
    *
    * @param organizationId organizationId
    * @param dto dto
    * @return ResponseEntity<List<SysDepartmentDTO>>
    */
    @ApiOperation(value = "options", tags = {"部门" },  notes = "SysDepartment-options ")
    @PostMapping("sys_organizations/{organizationId}/sys_departments/options")
    public ResponseEntity<List<SysDepartmentDTO>> optionsByOrganizationId
            (@PathVariable("organizationId") String organizationId, @Validated @RequestBody SysDepartmentDTO dto) {
        SysDepartment domain = sysDepartmentDtoMapping.toDomain(dto);
        domain.setOrganizationId(organizationId);
        List<SysDepartment> rt = sysDepartmentService.options(domain);
        return ResponseEntity.status(HttpStatus.OK).body(sysDepartmentDtoMapping.toDto(rt));
    }

    /**
    * ParentIds 部门
    * 
    *
    * @param organizationId organizationId
    * @param id id
    * @param dto dto
    * @return ResponseEntity<List<String>>
    */
    @ApiOperation(value = "ParentIds", tags = {"部门" },  notes = "SysDepartment-ParentIds ")
    @PostMapping("sys_organizations/{organizationId}/sys_departments/{id}/parentids")
    public ResponseEntity<List<String>> parentIdsByOrganizationIdAndId
            (@PathVariable("organizationId") String organizationId, @PathVariable("id") String id, @Validated @RequestBody SysDepartmentDTO dto) {
        SysDepartment domain = sysDepartmentDtoMapping.toDomain(dto);
        domain.setId(id);
        List<String> rt = sysDepartmentService.parentIds(domain);
        return ResponseEntity.status(HttpStatus.OK).body(rt);
    }

    /**
    * 保存Save 部门
    * 
    *
    * @param organizationId organizationId
    * @param dto dto
    * @return ResponseEntity<SysDepartmentDTO>
    */
    @ApiOperation(value = "保存Save", tags = {"部门" },  notes = "SysDepartment-Save ")
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','uaa-SysDepartment-Save-all') or hasPermission(this.sysDepartmentDtoMapping.toDomain(#dto),'uaa-SysDepartment-Save')")
    @PostMapping("sys_organizations/{organizationId}/sys_departments/save")
    public ResponseEntity<SysDepartmentDTO> saveByOrganizationId
            (@PathVariable("organizationId") String organizationId, @Validated @RequestBody SysDepartmentDTO dto) {
        SysDepartment domain = sysDepartmentDtoMapping.toDomain(dto);
        domain.setOrganizationId(organizationId);
        sysDepartmentService.save(domain);
        SysDepartment rt = domain;
        return ResponseEntity.status(HttpStatus.OK).body(sysDepartmentDtoMapping.toDto(rt));
    }

    /**
    * SubIds 部门
    * 
    *
    * @param organizationId organizationId
    * @param id id
    * @param dto dto
    * @return ResponseEntity<List<String>>
    */
    @ApiOperation(value = "SubIds", tags = {"部门" },  notes = "SysDepartment-SubIds ")
    @PostMapping("sys_organizations/{organizationId}/sys_departments/{id}/subids")
    public ResponseEntity<List<String>> subIdsByOrganizationIdAndId
            (@PathVariable("organizationId") String organizationId, @PathVariable("id") String id, @Validated @RequestBody SysDepartmentDTO dto) {
        SysDepartment domain = sysDepartmentDtoMapping.toDomain(dto);
        domain.setId(id);
        List<String> rt = sysDepartmentService.subIds(domain);
        return ResponseEntity.status(HttpStatus.OK).body(rt);
    }

    /**
    * 查询FetchDefault 部门
    * 
    *
    * @param organizationId organizationId
    * @param dto dto
    * @return ResponseEntity<List<SysDepartmentDTO>>
    */
    @ApiOperation(value = "查询FetchDefault", tags = {"部门" },  notes = "SysDepartment-FetchDefault ")
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','uaa-SysDepartment-FetchDefault-all') or hasPermission(#dto,'uaa-SysDepartment-FetchDefault')")
    @PostMapping("sys_organizations/{organizationId}/sys_departments/fetchdefault")
    public ResponseEntity<List<SysDepartmentDTO>> fetchDefaultByOrganizationId
            (@PathVariable("organizationId") String organizationId, @Validated @RequestBody SysDepartmentFilterDTO dto) {
        dto.setOrganizationIdEQ(organizationId);
        SysDepartmentSearchContext context = sysDepartmentFilterDtoMapping.toDomain(dto);
        Page<SysDepartment> domains = sysDepartmentService.searchDefault(context) ;
        List<SysDepartmentDTO> list = sysDepartmentDtoMapping.toDto(domains.getContent());
            return ResponseEntity.status(HttpStatus.OK)
            .header("x-page", String.valueOf(context.getPageable().getPageNumber()))
            .header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
            .header("x-total", String.valueOf(domains.getTotalElements()))
            .body(list);
    }

    /**
    * 查询FetchNesteds 部门
    * 
    *
    * @param organizationId organizationId
    * @param dto dto
    * @return ResponseEntity<List<SysDepartmentDTO>>
    */
    @ApiOperation(value = "查询FetchNesteds", tags = {"部门" },  notes = "SysDepartment-FetchNesteds ")
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','uaa-SysDepartment-FetchNesteds-all') or hasPermission(#dto,'uaa-SysDepartment-FetchNesteds')")
    @PostMapping("sys_organizations/{organizationId}/sys_departments/fetchnesteds")
    public ResponseEntity<List<SysDepartmentDTO>> fetchNestedsByOrganizationId
            (@PathVariable("organizationId") String organizationId, @Validated @RequestBody SysDepartmentFilterDTO dto) {
        dto.setOrganizationIdEQ(organizationId);
        SysDepartmentSearchContext context = sysDepartmentFilterDtoMapping.toDomain(dto);
        Page<SysDepartment> domains = sysDepartmentService.searchNesteds(context) ;
        List<SysDepartmentDTO> list = sysDepartmentDtoMapping.toDto(domains.getContent());
            return ResponseEntity.status(HttpStatus.OK)
            .header("x-page", String.valueOf(context.getPageable().getPageNumber()))
            .header("x-per-page", String.valueOf(context.getPageable().getPageSize()))
            .header("x-total", String.valueOf(domains.getTotalElements()))
            .body(list);
    }


    /**
    * 批量新建部门
    * @param dtos
    * @return ResponseEntity<Boolean>
    */
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','uaa-SysDepartment-Create-all')")
    @ApiOperation(value = "批量新建部门", tags = {"部门" },  notes = "批量新建部门")
	@PostMapping("sys_departments/batch")
    public ResponseEntity<Boolean> createBatch(@RequestBody List<SysDepartmentDTO> dtos) {
        sysDepartmentService.createBatch(sysDepartmentDtoMapping.toDomain(dtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    /**
    * 批量删除部门
    * @param ids ids
    * @return ResponseEntity<Boolean>
    */
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','uaa-SysDepartment-Remove-all')")
    @ApiOperation(value = "批量删除部门", tags = {"部门" },  notes = "批量删除部门")
	@DeleteMapping("sys_departments/batch")
    public ResponseEntity<Boolean> removeBatch(@RequestBody List<String> ids) {
        sysDepartmentService.removeBatch(ids);
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    /**
    * 批量更新部门
    * @param dtos
    * @return ResponseEntity<Boolean>
    */
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','uaa-SysDepartment-Update-all')")
    @ApiOperation(value = "批量更新部门", tags = {"部门" },  notes = "批量更新部门")
	@PutMapping("sys_departments/batch")
    public ResponseEntity<Boolean> updateBatch(@RequestBody List<SysDepartmentDTO> dtos) {
        sysDepartmentService.updateBatch(sysDepartmentDtoMapping.toDomain(dtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    /**
    * 批量保存部门
    * @param dtos
    * @return ResponseEntity<Boolean>
    */
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','uaa-SysDepartment-Save-all')")
    @ApiOperation(value = "批量保存部门", tags = {"部门" },  notes = "批量保存部门")
	@PostMapping("sys_departments/savebatch")
    public ResponseEntity<Boolean> saveBatch(@RequestBody List<SysDepartmentDTO> dtos) {
        sysDepartmentService.saveBatch(sysDepartmentDtoMapping.toDomain(dtos));
        return  ResponseEntity.status(HttpStatus.OK).body(true);
    }

    /**
    * 批量导入部门
    * @param config 导入模式
    * @param ignoreError 导入中忽略错误
    * @return ResponseEntity<ImportResult>
    */
    @PreAuthorize("hasAnyAuthority('ROLE_SUPERADMIN','uaa-SysDepartment-Save-all')")
    @ApiOperation(value = "批量导入部门", tags = {"部门" },  notes = "批量导入部门")
	@PostMapping("sys_departments/import")
    public ResponseEntity<ImportResult> importData(@RequestParam(value = "config" , required = false) String config ,@RequestParam(value = "ignoreerror", required = false, defaultValue = "true") Boolean ignoreError ,@RequestBody List<SysDepartmentDTO> dtos) {
        return  ResponseEntity.status(HttpStatus.OK).body(sysDepartmentService.importData(config,ignoreError,sysDepartmentDtoMapping.toDomain(dtos)));
    }

}
